<admintpl file="header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:U('NewsColumnEntrance/index',array($id_type=>$id_val))}">入口列表</a></li>
        <!-- <li><a href="#" onclick="addEntrance('{$column_id}');">添加栏目</a></li> -->
        <li><a href="{:U('NewsColumnEntrance/addEntrance',array($id_type=>$id_val))}" >添加入口</a></li>
        <li><a href="{:U('NewsColumnEntrance/entranceManageList',array($id_type=>$id_val))}" >入口管理</a></li>
    </ul>
    <form class="form-horizontal js-ajax-form" action="{:U('NewsColumn/index')}" method="post">
        <table class="table table-hover table-bordered">
            <thead>
            <tr>
                <th>序号</th>
                <th>入口标题</th>
                <th>副标题</th>
                <th>创建时间</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <foreach name="list" item="vo" key="keys">
                <tr>
                    <td>{$keys+1}</td>
                    <td><input type="text" name="title" id="entrance_title_{$vo.entrance_id}" value="{$vo.title}" disabled="disabled" size="4"  class="input_edit">
                        <a id="edit_title_{$vo.entrance_id}" href='javascript:void(0);' onclick="update_title('{$vo.entrance_id}','title')" class="edit_sub">修改</a>
                        <input type="hidden" name="old_title" id="old_title_{$vo.entrance_id}" value="{$vo.title}">
                    </td>
                    <td><input type="text" name="title" id="entrance_subtitle_{$vo.entrance_id}" value="{$vo.subtitle}" disabled="disabled" size="4"  class="input_edit">
                        <a id="edit_subtitle_{$vo.entrance_id}" href='javascript:void(0);' onclick="update_title('{$vo.entrance_id}','subtitle')" class="edit_sub">修改</a>
                        <input type="hidden" name="old_subtitle" id="old_subtitle_{$vo.entrance_id}" value="{$vo.subtitle}">
                    </td>
                    <!--<td><input type="text" name="weight" id="weight{$vo.type_id}" value="{$vo.weight}" disabled="disabled" size="4"  class="input_edit">
                        <a id="edit_weight_{$vo.type_id}" href='javascript:void(0);' onclick="update_weight('{$vo.type_id}','weight')" class="edit_sub">修改</a>
                        <input type="hidden" name="old_weight" id="old_weight_{$vo.type_id}" value="{$vo.weight}">
                    </td>  -->
                    <td>
                    	{$vo.create_time}
                    </td>
                    <td>
                    	<if condition="$vo['status'] eq '0' ">
                    		未开启
                    	<else/>
                    		已开启
                    	</if>
                    </td>
                    <td>
                    <a href="{:U('NewsColumnEntrance/addEntrance',array($id_type=>$id_val,'entrance_id'=>$vo['entrance_id']))}" >编辑</a>
                    <a href='{:U("Admin/NewsColumnEntrance/del",array("entrance_id"=>$vo["entrance_id"]))}' class="js-ajax-dialog-btn"
                           data-msg="确定要删除此入口吗？">删除</a>
                     </td>
                </tr>
            </foreach>
            </tbody>
        </table>
    </form>
    <div class="pagination">{$page}</div>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>
    function update_title(entrance_id,type){
        if(type == 'weight'){
            edit_column = $("#edit_weight_"+type_id).html();
            column_befor = $("#old_weight_"+type_id).val();//原权重值
            column  = $("#weight"+type_id).val(); //现权重值
            now_input_type = $("#weight" + type_id); //权重 ID
            now_edit_type  = $("#edit_weight_" + type_id);  //修改 按钮ID
        }else if(type == 'title'){
            edit_column = $("#edit_title_"+entrance_id).html();
            column_befor = $("#old_title_"+entrance_id).val();//原栏目名称值
            column  = $("#entrance_title_"+entrance_id).val(); //现栏目名称值
            now_input_type = $("#entrance_title_" + entrance_id); //栏目名称 ID
            now_edit_type  = $("#edit_title_" + entrance_id);  //修改 按钮ID
        }else if(type == 'subtitle'){
            edit_column = $("#edit_subtitle_"+entrance_id).html();
            column_befor = $("#old_subtitle_"+entrance_id).val();//原栏目名称值
            column  = $("#entrance_subtitle_"+entrance_id).val(); //现栏目名称值
            now_input_type = $("#entrance_subtitle_" + entrance_id); //栏目名称 ID
            now_edit_type  = $("#edit_subtitle_" + entrance_id);  //修改 按钮ID
        }

        if(edit_column == "修改"){
            //处理 同时存在多个input编辑问题
            $(".input_edit").attr("disabled", "disabled");
            $(".edit_sub").html("修改");

            now_input_type.removeAttr("disabled");
            now_edit_type.html("确认");
        }else{
            if(column_befor == column){
                now_input_type.attr("disabled", "disabled");
                now_edit_type.html("修改");
            }else {
                $.post("{:U('NewsColumnEntrance/editColumnEntrance')}", {type: type, entrance_id: entrance_id, val: column},
                        function (result) {
                            if (result == 1) {
                                now_input_type.attr("disabled", "disabled");
                                now_edit_type.html("修改");
                                location.reload()
                            }else{
                                alert("异常!")
                            }
                        }
                );
            }
        }
    }

//    function addEntrance(column_id, entrance_id){
//    	if(entrance_id){
//    		var andfiled = '&column_id='+column_id+'&entrance_id='+entrance_id;
//    		var layer_title = '编辑';
//    	}else{
//    		var andfiled = '&column_id='+column_id;
//    		var layer_title = '添加';
//    	}
//        layer.open({
//            type: 2,
//            //skin: 'layui-layer-lan',
//            title: layer_title+'入口',
//            fix: false,
//            shadeClose: true,
//            maxmin: true,
//            area: ['1000px', '500px'],
//            content: "<?php echo U('Admin/NewsColumnEntrance/addEntrance')?>"+andfiled,
//            end: function(){
//                location.reload();
//            }
//        });
//    }
//    function refresh_news(news_id){
//        $.post("<?php echo U('Admin/NewsManage/refreshNews')?>",{news_id:news_id}, function(result){
//            if(result == '1'){
//                var msg = '刷新成功';
//            }else{
//                var msg = '刷新失败';
//            }
//
//            alert(msg);
//            window.location.reload();
//        });
//    }
//    $(document).ready(function () {
//
//        $('input[name="query_form_btn"]').click(function () {
//            $('#query_form').attr('action', $(this).attr('data-action'));
//            $('#query_form').submit();
//        });
//        $("#category").val("{$formParam.categoryId}");
//
//
//    });

</script>
</body>
</html>